package com.yf.controller;


import com.yf.dto.Message;
import com.yf.dto.Result;
import com.yf.entity.MonthList;
import com.yf.myException.ExceptionEnum;
import com.yf.myException.NewException;
import com.yf.service.StatisticsService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@CrossOrigin
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取上周每天数据
     * @return
     */
    @RequiresRoles(value = {"teacher","manager"},logical = Logical.OR)
    @RequestMapping(value = "/getHomeWeek")
    public Result getHomeWeek(){
        try {
            List list = statisticsService.getStudentByLastWeek2();
            Result result = new Result();
            result.setMessage(new Message());
            result.setObj(list);
            return result;
        } catch (Exception e) {
            throw new NewException(ExceptionEnum.ERROR_GET);
        }
    }

    /**
     * 获取前六个月数据
     * @return
     */
    @RequiresRoles(value = {"teacher","manager"},logical = Logical.OR)
    @RequestMapping(value = "/getHomeMonth")
    public Result getHomeMonth(){
        try {
            MonthList list = statisticsService.getMonthCountList();
            Result result = new Result();
            result.setMessage(new Message());
            result.setObj(list);
            return result;
        } catch (Exception e) {
            throw new NewException(ExceptionEnum.ERROR_GET);
        }
    }

}
